package com.hsmw.api.controller.pub;

import com.hsmw.domain.HsmwOrder;

import java.util.UUID;

public class GenerateIDUtils {

    public static String generateId(HsmwOrder entity){
        return String.format("%1$s%2$ts%3$s", obtainAbbreviation(entity), System.currentTimeMillis(), createUID());
    }
    private static String modelSuffix = null;

    private  static  String obtainAbbreviation(HsmwOrder entity){
        if(modelSuffix == null){
            String sn = entity.getClass().getSimpleName();
            modelSuffix = sn.split("\\$\\$EnhancerByCGLIB\\$\\$")[0].replaceAll("[^A-Z]", "");
        }
        return modelSuffix;
    }

    private static String createUID() {
        String uuid = UUID.randomUUID().toString();
        return uuid.substring(uuid.lastIndexOf("-") + 1, uuid.length());
    }
}
